<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<!DOCTYPE html>
<html lang="en">
  <head>
     <%@include file="/WEB-INF/jsp/common/style.jsp"%>
          <c:set var="ctx" value="${pageContext.request.contextPath}"/>
	<script type="text/javascript">
		var basePath = "${ctx}";
	</script>
    <link href="${ctx}/css/jquery.treeview.css" rel="stylesheet">
    
    <link rel="Favicon Icon" href="favicon.ico">
   <script type="text/javascript" src="${ctx}/js/jquery.min.js"></script>
    <script src="${ctx}/js/jquery.treeview.js" type="text/javascript"> </script>
  </head>
  <body>
    <div id="wrap">
    <input type="hidden" id="itemId" value="${model.productItem.id}"> 
    <input  type="hidden" name="catId3" id="catId3" value="${model.productItem.category3Id}" />
    <input  type="hidden" name="catId2" id="catId2" />
    <input  type="hidden" name="catId1" id="catId1" />
   <div class="main_container" id="forms_page">
     	<div class="row-fluid">
          <div class="widget widget-padding span12">
              <div class="widget-forms clearfix" style="padding-top:15px">
              	 <div class="form-horizontal">
              	 
              	  <div class="control-group">
                    <label class="control-label" ><font color="red">*</font>产品名称</label>
                    <div class="controls">
                      <input name=itemName id="itemName"  maxlength="100"   type="text"   value="${model.productItem.itemName}"  class="w300" />                      
                    </div>
                  </div>
              	 
                  
                  <div class="control-group">
                    <label class="control-label" >产品建议价</label>
                    <div class="controls">
                      <input name=suggestPrice id=suggestPrice  maxlength="20"   type="text" class="w300"
						value="${model.productItem.suggestPrice}" 
					 onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false"
					   />                      
                    </div>
                  </div>
                  
                  <div class="control-group">
                    <label class="control-label"><font color="red">*</font>关联品类</label>
                    <div class="controls" id="treediv1">
                      <input   type="text"  onclick="showCategory()" autocomplete="off"  name="catName" id="catName" class="w300"   value="${model.catName}"
                       maxlength="11" >
                       	<div id="treediv"  class="treecategory" >
					  		
				    	</div>
                    </div>
                  </div>
                  
                  <div class="control-group">
                    <label class="control-label"><font color="red">*</font>项目名称</label>
                    <div class="controls">
                        <select  id="projectId"  type="select" class="w300">
                           	<option value="" <c:if test="${model.productItem.projectId==null}">selected="selected"</c:if>>请选择</option>
					   			<c:forEach items="${model.projects}" var="lo" varStatus="itemStatus">
					               <option value="${lo.id}" <c:if test="${model.productItem.projectId==lo.id}">selected="selected"</c:if>>${lo.projectName}</option>
					        </c:forEach>  
                        </select>
                     </div>
                  </div>

				<div class="control-group">
                    <label class="control-label"><font color="red">*</font>核心产品</label>
                    <div class="controls">
                     <label class="radio">
                        <input name="isCore"  type="radio" 
                        <c:if test="${model.productItem.isCore==1}">checked="checked"</c:if>  
                        value="1">
                        	是
                      </label>
                      <label class="radio">
                        <input name="isCore"  type="radio" 
                        <c:if test="${model.productItem.isCore==0}">checked="checked"</c:if>  
                        value="0">
                     		否
                      </label>
                    </div>
                  </div>
                  
                  <div class="control-group">
                    <label class="control-label"><font color="red">*</font>自有渠道产品</label>
                    <div class="controls">
                     <label class="radio">
                        <input name="isSelfChannel"  type="radio" 
                        	 <c:if test='${model.productItem.isSelfChannel==1}'>checked="checked"</c:if>  
                        value="1">
                        	是
                      </label>
                      <label class="radio">
                        <input name="isSelfChannel"  type="radio" 
                        <c:if test="${model.productItem.isSelfChannel==0}">checked="checked"</c:if>  
                        value="0">
                     		否
                      </label>
                    </div>
                    </div>
                       </div>
                  </div>

              
            </div>
           
          </div>
          <div class="row-fluid">
          	<div class="footbtn"> 
          	 	<button class="btn btn-primary" type="submit"  onclick="save()">保存</button>
               <button class="btn" type="button" onclick="backIndex()">取消</button>
               </div>
          </div>
        </div>  
     
   	</div>
  </body>
  <script type="text/javascript">
  $(document).ready(function(){
		loadtree();
	});
	function loadtree(){
		postData="1=1";
		var domainUrl="${pageContext.request.contextPath}/set/category/cateview";
		 $.ajax({
	           type: "POST",
	           url: domainUrl,
	           data: postData,
	           contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	           async: true, // 同步  true 异步。默认是异步
	           error: function(resultdata) {
	           	//layer.closeAll();
	           },
	           success: function(resultdata) {
					$('#treediv').html(resultdata);
					 $("#tree").treeview({  
			        	  collapsed: true  
		    			});  
				 	 $("#treediv").hide();
	           }
	       });
	}
	
	function showCategory(){
		$("#treediv").show();
	}
	function selectcategory(cateLevel,categoryId,category3Name,category2Name,category1Name){
		
		if(cateLevel==1){
			//$('#catName').val(category1Name);
		}
		if(cateLevel==2){
			//$('#catName').val(category1Name + ">" + category2Name);
		}
		if(cateLevel==3){
			$('#catId3').val(categoryId);
			$('#catName').val(category1Name + ">" + category2Name + ">" + category3Name);
			$("#treediv").hide();
		}		
		
	}
	$("#treediv1").hover(function (){  
       // $(".content").show();  
	 	},function (){  
	 	$("#treediv").hide();  
	 });  

  function save(){
		var postData="&itemId=" +$('#itemId').val() ;
		
		var itemName=$('#itemName').val();
		if(itemName==''){
			layer.alert('请输入产品名称');
	    	return;
		}
		postData=postData + "&itemName=" + encodeURIComponent(itemName);
		
		var projectId=$('#projectId').val();
		if(projectId==''){
			layer.alert('请选择关联项目');
	    	return;
		}
		postData=postData + "&projectId=" + encodeURIComponent(projectId);
		
		
		var catId3=$('#catId3').val();
		if(catId3==''){
			layer.alert('请选择分类');
	    	return;
		}
		postData=postData + "&catId3=" + catId3;
		
		var suggestPrice=$('#suggestPrice').val();
		postData=postData + "&suggestPrice=" + encodeURIComponent(suggestPrice);
		
		var isCore= $("input[name='isCore']:checked").val();
		if(isCore==undefined){
			layer.alert('请选择是否核心');
	    	return;
		}
		postData=postData + "&isCore=" + isCore;
		
		var isSelfChannel= $("input[name='isSelfChannel']:checked").val();
		if(isSelfChannel==undefined){
			layer.alert('请选择是否自有渠道');
	    	return;
		}
		postData=postData + "&isSelfChannel=" + isSelfChannel;
		
	    layer.load(1, {shade: [0.5,'#fff']});
	    //alert(postData);
	    $.ajax({
	        type: "POST",
	        url: "save",
	        data: postData,
	        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	        async: true, // 同步  true 异步。默认是异步
	        dataType: 'json',
	        error: function(resultdata) {
	        	layer.closeAll();
	        },
	        success: function(resultdata) {
	        	layer.closeAll();
	            if(resultdata.returnCode=="0000"){               	
	            	layer.alert('操作成功',{icon: 1}, function(){
	            	 	 parent.editReturn();
	            		//layer.closeAll(); 
	            		 //layer.closeAll();
	            		//window.location.href="${pageContext.request.contextPath}/distrbutor/inventory/index";
	            	});
	            }else{
	            	layer.alert(resultdata.returnMessage);
	            }
	        }
	    });
	}
  function backIndex(){	  
 	 parent.editReturn();
  }
	</script>
</html>
